//--------------------------------------------------------------------------------
// This file is a portion of the D2D1Renderer.  It is distributed
// under the MIT License, available in the root of this distribution and 
// at the following URL:
//
// http://www.opensource.org/licenses/mit-license.php
//
// Copyright (c) Mirco Timmermann
//
//--------------------------------------------------------------------------------
#pragma once

#ifndef _D2_TAB_CONTAINER_H
#define _D2_TAB_CONTAINER_H

#include "..\..\DisplayObjectContainer.h"
#include "..\..\..\geom\Point2f.h"
#include "..\..\..\geom\Rect.h"

#include <string>


using namespace D2;

class TabContainer : public D2::DisplayObjectContainer {
public:
	struct Tab {
		std::string name;
		bool highlight;
		DisplayObjectContainer* container;

		Tab(std::string name, int width, int height) {
			this->name = name;
			highlight = false;
			container = new DisplayObjectContainer(0, 0, width, height);
		}

		~Tab() {
			delete container;
		}
	};

public:
	TabContainer(int x, int y, int width, int height);
	virtual ~TabContainer(void);
	
public:
	int _tabWidth;
	bool _invert;
	bool tabLabelContainerAutoWidth; //if the complete area of the tab labels is hitarea, or only where tabs are.
	int _tabHeight;
	int _tabDistance;

private:
	Tab* _currentSelectedTab;
	int _mouseOverTabIndex;

	DisplayObjectContainer* _tabLabelContainer;

	std::vector<Tab*> _tabs;

public:
	Tab* AddTab(std::string name);
	Tab* AddTabAt(std::string name, int index);

	void RemoveTab(Tab* tab);
	void RemoveTabAt(int index);
	void RemoveTabByName(std::string name);

	Tab* SelectTab(Tab* tab);
	Tab* SelectTabAt(int index);
	Tab* SelectTabByName(std::string name);

	int GetTabIndexByName(std::string name);
	Tab* GetTabByName(std::string name);

//
	void calculateTabContainerTransform();

//
private:
	int GetTabIndexByPosition(int x, int y);

//public:
	//virtual void OnMouseDown0(const MouseEvent &e);

public:
	void ON_MOUSE_DOWN0_tabLabelContainer(const Event &event);
	void ON_MOUSE_MOVE_tabLabelContainer(const Event &event);
	void ON_MOUSE_OUT_tabLabelContainer(const Event &event);
	
	/*
	//@IMouseListener
	virtual void OnMouseMove(const MouseEvent &e);

	//@IInput
	//virtual void OnMouseOver(const MouseEvent &e);
	virtual void OnMouseOut(const MouseEvent &e);
	virtual void OnFocusLost(const MouseEvent &e);
	
	virtual void OnMouseDown0(const MouseEvent &e);
	virtual void OnMouseUp0(const MouseEvent &e);
	virtual void OnMouseLeave0(const MouseEvent &e);
	virtual void OnMouseRaise0(const MouseEvent &e);
	
	virtual void OnMouseDrag0(const MouseEvent &e);

	virtual void OnMouseDown1(const MouseEvent &e);
	virtual void OnMouseUp1(const MouseEvent &e);
	virtual void OnMouseRaise1(const MouseEvent &e);
	virtual void OnMouseLeave1(const MouseEvent &e);
	*/
////////////////////////////VISUALISATION//////////////////////////

	virtual bool Draw(Direct2DContext* ctx, D2D1::Matrix3x2F* mtx = 0);

private:
	void DrawTabs(Direct2DContext* ctx);
	void DrawContainerForm(Direct2DContext* ctx);

};

#endif